import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { IDevicesVO } from '@/api/business/charger/types'

enum Api {
  list = '/charger/list',
  delete = '/charger/delete',
  batchDelete = '/charger/batchDelete',
  add = '/charger/add',
  edit = '/charger/edit',
  detail = '/charger/detail',
  startCharge = '/charger/startCharge',
  timeConfig = '/charger/timeConfig',
  qrcodeConfig = '/charger/qrcodeConfig',
  priceConfig = '/charger/priceConfig',
  reboot = '/charger/reboot',
  logs = '/charger/logs',
  changeStatus = '/charger/changeStatus',
}

// 获取列表
export const getChargerList = (data: any): AxiosPromise<any> => {
  return request({
    url: Api.list,
    method: 'post',
    data,
  })
}

// 获取日志列表
export const getChargerLogList = (data: any): AxiosPromise<any> => {
  return request({
    url: Api.logs,
    method: 'post',
    data,
  })
}

// 启动充电
export const startCharge = (data: any) => {
  return request({
    url: Api.startCharge,
    method: 'post',
    data,
  })
}

// 校时
export const timeConfig = (data: string) => {
  return request({
    url: Api.timeConfig,
    method: 'post',
    data,
  })
}

// 下发二维码
export const qrcodeConfig = (data: string) => {
  return request({
    url: Api.qrcodeConfig,
    method: 'post',
    data,
  })
}

// 下发计价规则
export const priceConfig = (data: string) => {
  return request({
    url: Api.priceConfig,
    method: 'post',
    data,
  })
}

// 下发计价规则
export const reboot = (data: string) => {
  return request({
    url: Api.reboot,
    method: 'post',
    data,
  })
}

// 删除
export const deleteCharger = (data: string) => {
  return request({
    url: Api.delete,
    method: 'post',
    data,
  })
}
// 批量删除
export const batchDeleteChargers = (data: (string | number)[]) => {
  return request({
    url: Api.batchDelete,
    method: 'post',
    data,
  })
}

// 编辑、保存
export const saveCharger = (data: IDevicesVO) => {
  return request({
    url: data.id ? Api.edit : Api.add,
    method: 'post',
    data,
  })
}

// 获取设备详情
export const getChargerDetail = (data) => {
  return request({
    url: Api.detail,
    method: 'post',
    data,
  })
}

// 状态修改
export function changeStatus(id: string | number, status: number) {
  const data = {
    id,
    status,
  }
  return request({
    url: Api.changeStatus,
    method: 'post',
    data,
  })
}
